﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;

namespace PFWFA
{
    public partial class Race : Form
    {
        ArrayList list = new ArrayList();
        Random rnd = new Random();
        int r;

        public Race()
        {
            InitializeComponent();
            list.Add(racer1);
            list.Add(racer2);
            list.Add(racer3);
            list.Add(racer4);
            lblWinner.Text = " ";
        }

        private bool checkPct(ProgressBar pb, int pct)
        {
            return pb.Value >= pct;
        }

        private void btnGo_Click(object sender, EventArgs e)
        {
            foreach (ProgressBar i in list) 
            {
                r = rnd.Next(1,11);
                if (i.Value + r > 100)
                {
                    i.Value = 100;
                }
                else
                {
                    i.Value += r;
                }
                if (checkPct(i, 100))
                {
                    lblWinner.ForeColor = i.ForeColor;
                    lblWinner.Text = "WINNER!!!!";
                }
            }
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            racer1.Value = 0;
            racer2.Value = 0;
            racer3.Value = 0;
            racer4.Value = 0;
            lblWinner.Text = " ";
        }
    }
}
